<template>
  <el-dialog title="退运费"
             :close-on-click-modal="false"
             :visible.sync="visible"
             @close="close">
    <div style="margin-left: 40px;margin-bottom: 10px;color: #999999">退回运费（总共{{model.freight}} 已退{{model.refundFreight}}）</div>
    <el-form ref="dataForm" :model="dataForm" label-width="110px" :rules="rules">
      <el-form-item label="退运费：" prop="freight">
        <el-input v-model="dataForm.freight" oninput="value=value.replace(/^\.+|[^\d.]/g,'')"> style="width: 50%"  placeholder="请输入退运费" clearable></el-input>
      </el-form-item>
    </el-form>
    <div style="display: flex;justify-content: center">
      <el-button type="primary" @click.stop="save" :loading="loading">确定</el-button>
      <el-button @click.stop="close">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    name: 'backFreight',
    data () {
      return {
        visible: false,
        loading: false,
        model: {},
        dataForm: {
          freight: ''
        },
        rules: {
          freight: [
            {
              required: true, message: '请输入退运费', trigger: 'blur'
            }
          ]
        }
      }
    },
    methods: {
      init (model) {
        this.visible = true
        this.model = model
      },
      save () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: this.$http.adornUrl('/v1/apply/charging/refund/freight'),
              method: 'post',
              data: this.$http.adornData({
                id: this.model.id,
                freight: this.dataForm.freight
              })
            }).then(({ data }) => {
              this.loading = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            })
          }
        })
      },
      close () {
        this.visible = false
      }
    }
  }
</script>

<style scoped>

</style>
